<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    button {
      border: none;
      outline: none;
    }
    .current {
      background-color: #56a5f1;
      color: #fff;
    }
  </style>
</head>
<body>
  <div id="app">
    <button @click="toggle(1)" :class="{current: active==1}" @keyup.tab="toggle(1)">评论管理</button>
    <button @click="toggle(2)" :class="{current: active==2}" @keyup.tab="toggle(2)">评论发布</button>
    <div v-show="active === 1">
      <input type="text" placeholder="昵称" v-model="name">
      <input type="text" placeholder="内容" v-model="content">
      <button @click="submit">立即提交</button>
    </div>
    <div v-show="active === 2">
      <div v-for="(item, index) in list" :key="index">
        <p>评论人：{{item.name}}</p>
        <p>评论内容：{{item.content}}</p>
        <p>评论时间：{{item.time}}</p>
      </div>
    </div>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        // 显示哪个模块，1是管理2是发布
        active: 1,
        list: [],
        name: '',
        content: ''
      },
      methods: {
        toggle(num) {
          // 评论管理和发布之间的切换
          this.active = num;
        },
        submit() {
          this.list.push({
            name: this.name,
            content: this.content,
            time: '2021-09-24'
          })
        },
        show() {
          console.log(666);
        }
      },
    })
  </script>
</body>
</html>